function [Xc,Xs,settings] = create_training(settings)
% create training set (Xc and Xs)

if settings.verbose, fprintf('creating training set\n'); end

if ischar(settings.stego)
    % single feature file

    S = load(settings.stego,'names');
    C = load(settings.cover,'names');
    [Sn,Sx] = sort(S.names); clear S
    [Cn,Cx] = sort(C.names); clear C
    names = intersect(Cn,Sn);
    Ckeep = ismember(Cn,names); clear Cn
    Skeep = ismember(Sn,names); clear Sn

    % create training and testing parts
    rand('state',settings.seed_trntst);
    names_rnd = names(randperm(length(names)));
    trn_names = names_rnd(1:round(settings.ratio*length(names)));
    TRN_ID = ismember(names,trn_names);
    clear trn_names names_rnd

    % create training part from C
    C = load(settings.cover,'F');
    C = C.F(Cx,:);
    C = C(Ckeep,:); clear Ckeep Cx
    C(~TRN_ID,:) = []; Xc = C; clear C

    % create training part from S
    S = load(settings.stego,'F');
    S = S.F(Sx,:); S = S(Skeep,:); clear Skeep Sx
    S(~TRN_ID,:) = []; Xs = S; clear S
elseif isstruct(settings.stego)
    % create training and testing parts
    rand('state',settings.seed_trntst);
    M = size(settings.cover.F, 1);
    rnd = randperm(M);
    TRN_ID = rnd(1:round(settings.ratio*M));clear rnd M

    % create training part from C
    C = settings.cover.F;
    C(~TRN_ID,:) = []; Xc = C; clear C

    % create training part from S
    S = settings.stego.F;
    S(~TRN_ID,:) = []; Xs = S; clear S
else
    % multiple feature files
    [S,C,Sn,Sx,Cn,Cx,Ckeep,Skeep] = deal(cell(length(settings.stego),1));
    for i=1:length(settings.stego)
        S{i} = load(settings.stego{i},'names');
        C{i} = load(settings.cover{i},'names');
        [Sn{i},Sx{i}] = sort(S{i}.names);
        [Cn{i},Cx{i}] = sort(C{i}.names);
        if i==1
            names = intersect(Cn{i},Sn{i});
        else
            names = intersect(intersect(Cn{i},Sn{i}),names);
        end
    end
    for i=1:length(settings.stego)
        Ckeep{i} = ismember(Cn{i},names);
        Skeep{i} = ismember(Sn{i},names);
    end
    
    % create training and testing parts
    rand('state',settings.seed_trntst);
    names_rnd = names(randperm(length(names)));
    trn_names = names_rnd(1:round(settings.ratio*length(names)));
    TRN_ID = ismember(names,trn_names);
    clear trn_names names_rnd

    Xc=[];Xs=[];
    for i=1:length(settings.stego)
        % create training part from cover
        C = load(settings.cover{i},'F');
        C = C.F(Cx{i},:); C = C(Ckeep{i},:);
        C(~TRN_ID,:) = []; Xc = [Xc C]; clear C

        % create training part from stego
        S = load(settings.stego{i},'F');
        S = S.F(Sx{i},:); S = S(Skeep{i},:);
        S(~TRN_ID,:) = []; Xs = [Xs S]; clear S
    end
end
settings.max_dim = size(Xs,2);

